from PyQt5.QtWidgets import QApplication, QFileDialog, QMessageBox, QDialog, QLabel
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QMovie
import sys

class FileDialog(QFileDialog):
    def __init__(self, mode, title, parent=None):
        super(FileDialog, self).__init__(parent)
        self.setAcceptMode(mode)
        self.setWindowTitle(title)
        self.setNameFilter("IMG(*.jpg)")
        if mode == QFileDialog.AcceptOpen:
            self.setFileMode(QFileDialog.ExistingFile)

    def getSelectFilePath(self):
        if self.exec() == QFileDialog.Accepted:
            return self.selectedFiles()[0]
        else:
            return None

class WarningMessageBox(QMessageBox):
    def __init__(self,  text, parent=None):
        super(WarningMessageBox, self).__init__(parent=parent)
        self.setWindowTitle("Warning")
        self.setStandardButtons(QMessageBox.Yes)
        self.setText(text)
        self.setIcon(QMessageBox.Warning)

class QuestionMessageBox(QMessageBox):
    def __init__(self,  text, parent=None):
        super(QuestionMessageBox, self).__init__(parent=parent)
        self.setWindowTitle("Question")
        self.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
        self.setText(text)
        self.setIcon(QMessageBox.Question)

class LoadingDialog(QDialog):
    def __init__(self, parent=None):
        super(LoadingDialog, self).__init__(parent=parent)
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.gifLb = QLabel(self)
        mv = QMovie("../Data/load1.gif")
        self.gifLb.setMovie(mv)
        mv.start()
        self.setFixedSize(100, 100)

def main():
    app = QApplication(sys.argv)

    # fd = FileDialog(QFileDialog.AcceptOpen, "test")
    #
    # print(fd.getSelectFilePath())
    ui = LoadingDialog().exec()

    sys.exit(app.exec())


if __name__ == "__main__":
    main()
